package com.example.MyRESTAssured.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class RESTAssuredController {


    /**
     * 使用controller，如果是范围json,必须加上@ResponseBody，否则他会去找对应的页面
     * @return
     */
    @RequestMapping(value = "/lotto",method = RequestMethod.GET )
    @ResponseBody
    public String makeGetRequest(){

        String res="{\n" +
                "\"lotto\":{\n" +
                " \"lottoId\":5,\n" +
                " \"winning-numbers\":[2,45,34,23,7,5,3],\n" +
                " \"winners\":[{\n" +
                "   \"winnerId\":23,\n" +
                "   \"numbers\":[2,45,34,23,3,5]\n" +
                " },{\n" +
                "   \"winnerId\":54,\n" +
                "   \"numbers\":[52,3,12,11,18,22]\n" +
                " }]\n" +
                "}\n" +
                "}";
        return res;
    }

    @RequestMapping(value = "/number",method = RequestMethod.GET )
    @ResponseBody
    public String validateNumberTypeGetRequest(){

        String res="{\n" +
                "\t\"price\": 11.11,\n" +
                "\t\"money\": 22.22,\n" +
                "\t\"cash\": 33.33\n" +
                "}";
        return res;
    }

    @RequestMapping(value = "/schema",method = RequestMethod.GET )
    @ResponseBody
    public String validateJsonSchemaGetRequest(){

        String res="{\n" +
                "\t\"id\": 10,\n" +
                "\t\"name\": \"jxiong\",\n" +
                "\t\"price\": 20\n" +
                "}";
        return res;
    }

    @RequestMapping(value = "/anonymous",method = RequestMethod.GET )
    @ResponseBody
    public String validateAnonymousJSONRootGetRequest(){

        String res="[1, 2, 3]";
        return res;
    }

}
